package org.com.ashen.web.voice.demo;

import java.util.*;

import org.com.ashen.web.voice.dto.MobileAndVariableDTO;
import org.com.ashen.web.voice.util.*;

/**
 * @Author yudejun
 * @Date 2020/8/5 10:31
 * @Version 1.0
 */
public class TestTemplateVariable {
	public static void main(String[] args) {
		send();
	}

	public static void send() {
		String appId = "EUCP-EMY-VOC0-CQ4E6";
		String secretKey = "104B0DF9E0AA645F";
		String host = "http://voice.b2m.cn:80";
		String templateId = "1666245986891002002";
		String timestamp = DateUtil.toString(new Date(), "yyyyMMddHHmmss");
		String signStr = appId + secretKey + timestamp;
		System.out.println("加密前sign:" + signStr);
		String sign = Md5.md5(signStr.getBytes());
		System.out.println("加密后sign:" + sign);//
		String mobiles = "13651949883";//
		String customJoinIds = "4567891230";
		Map<String, String> variableMap = new LinkedHashMap<>();
		variableMap.put("参数1", "12");
		variableMap.put("参数2", "张三");
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("appId", appId);
		param.put("timestamp", timestamp);
		param.put("sign", sign);
		param.put("templateId", templateId);
		List<MobileAndVariableDTO> list = new ArrayList<>();
		MobileAndVariableDTO mobileAndVariableDTO = new MobileAndVariableDTO();
		mobileAndVariableDTO.setCustomVoiceId(customJoinIds);
		mobileAndVariableDTO.setMobile(mobiles);
		mobileAndVariableDTO.setVariable(variableMap);
		list.add(mobileAndVariableDTO);
		param.put("variables", list);
		param.put("smsContent", "大萨达稍等阿萨德123124asda阿达");
		param.put("triggerConditions", "3");
		param.put("keyContent", "4");
		param.put("connectTime", "6");
		String url =host+ "/voice/templateVariableSend";
		String json = JsonHelper.toJsonString(param);
		System.out.println(json);
		// 组装报文发送
		HttpClient client = new HttpClient(60, 60, true);
		HttpRequestBody body;
		try {
			body = new HttpRequestBody(url, "utf-8", json, HttpClient.HttpMethod.POST, null, null);
		} catch (HttpErrorException e) {
			e.printStackTrace();
			return;
		}
		HttpResponseBody res = client.service(body);
		if (res.isSuccess() && res.getCode() == 200) {
			String rs1 = res.getResultString();
			System.out.println("发送短信收到响应报文" + rs1);
		}
	}
}
